<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<div id="app">
    {{msg}}==={{count}}==={{obj}}
    <hr>
    <button @click="count+=10">加</button>
    <button @click="handel">加2</button>




</div>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.min.js"></script>
<script>
    const vu = new Vue({
        el: "#app",
        data: {
            msg: 'hello vue',
            count: 10,
            obj: {
                num: 1
            }


        },
        methods: {
            handel() {
                this.obj.num += 2
            }

        },
        computed: {

        },
        watch: {
            //监听现有数据
            count(newValue, oldValue) {
                console.log(newValue, oldValue, 111)

            },
            //监听对象里面的数据变化
            //方法一
            // 'obj.num' () {
            //     console.log(122)
            // }
            //方法二
            obj: {
                handler(newVal) {
                    console.log(newVal.num, 222)

                },
                deep: true, //深度监听
                immediate: true //立即开启监听

            }
        }
    })
</script>






</body>

</html>